#define _CRT_SECURE_NO_WARNINGS 1
#include"test.h"

ListNode* reverseList(struct ListNode* head) {
    if (head == NULL)
        return head;
    ListNode* n1 = NULL;
    ListNode* n2 = head;
    ListNode* n3 = n2->next;
    while (n2) {
        n2->next = n1;
        n1 = n2;
        n2 = n3;
        if (n3)
            n3 = n3->next;
    }
    return n1;
}

ListNode* removeElements(struct ListNode* head, int val) {
    ListNode* pcur, * newhead, * newtail;
    pcur = head;
    newhead = newtail = NULL;
    while (pcur) {
        if (pcur->val != val) {
            if (newhead == NULL)
                newhead = newtail = pcur;
            else {
                newtail->next = pcur;
                newtail = newtail->next;
            }
        }
        pcur = pcur->next;
    }
    if (newtail)
        newtail->next = NULL;
    return newhead;
}

ListNode* middleNode(struct ListNode* head) {
    ListNode* slow = head;
    ListNode* fast = head;
    while (fast && fast->next) {
        slow = slow->next;
        fast = fast->next->next;
    }
    return slow;
}